package com.jmb.api.web.service.impl;

import com.jmb.api.common.utils.NoUtil;
import com.jmb.api.common.utils.RedisUtil;
import com.jmb.api.web.service.TempPostProcessorValueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.embedded.netty.NettyWebServer;
import org.springframework.stereotype.Service;

import javax.crypto.KEM;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class TempPostProcessorValueServiceImpl implements TempPostProcessorValueService {
    @Autowired
    private RedisUtil redisUtil;

    /**
     * 获取所有临时后置处理器值
     * @return map
     */
    @Override
    public Map<Object, Object> findAllTempValue() {
        return  redisUtil.hashEntries(NoUtil.TEMP_POST_PROCESSOR_NO);

    }

    /**
     *
     * 获取指定临时变量
     * @param key key
     * @return map
     */
    @Override
    public Map<Object, Object> findTempValueByValue(String key) {
        Object o = redisUtil.hashGet(NoUtil.TEMP_POST_PROCESSOR_NO, key);
        HashMap<Object, Object> hashMap = new HashMap<>();
        hashMap.put(key,o);
        return hashMap;
    }

    /**
     * 移除所有临时变量
     * @param
     */

    @Override
    public void removeAllTempValue() {
        redisUtil.hashDel(NoUtil.TEMP_POST_PROCESSOR_NO);

    }
    /**
     * 移除临时变量
     * @param key key
     */

    @Override
    public void removeTempValue(String key) {
        redisUtil.hashDel(NoUtil.TEMP_POST_PROCESSOR_NO,key);
        log.info("移除临时变量成功,key{}",key);

    }
}
